<?php
/**
 * issue queries from sql templates
 * retrieve results as resource, arrays, or objects
 * MySQL only for now
 * @use QueryTpl
 */
class DbStoreTool extends WakStorage {

	/**
	 * @static
	 * @param string $kit_id parent kit id
	 * @param array $cfg configuration data, will be merged with defaults
	 * @return wakTool
	 */
    function Factory($kit_id,$cfg) {
        return new DbStoreTool($kit_id,$cfg);
    }

	/**
	 * retrieve a query template from file
	 * @access public
	 * @param array|string $query_id query identifiers
	 * @return QueryTpl
	 */
	function getQueryTpl($query_id) {
		return $this->getItem($query_id);
	}

	/**
	 * issue a query and get result as brute resource
	 * @access public
	 * @param string| $query_id query identifiers
	 * @param array $parameters
	 * @return resource
	 * /
	function getResource($query_id,$parameters=array()) {

	}/**/

	/**
	 * issue a query and return a DbResult instance
	 * @access public
	 * @param string| $query_id query identifiers
	 * @param array $parameters
	 * @return DbStoreResult
	 */
	function getDbResult($query_id,$parameters=array()) {
		if (!$tpl=$this->getItem($query_id))
			return false;
		$sql=$tpl->render($parameters);
		return new DbStoreResult($sql);
	}

	/**
	 * @var array default config
	 */
	var $cfg=array(
		'storage'=>array(
			'search'=>'dbstore/{{id}}.tpl.sql'
			,'class'=>'DbStoreQueryTpl'));
}
